<template>
  <div>
    <div class="search">
      <crv-from v-bind="searchConfig" v-model="formData">
        <!-- <template #header> 高级检索 </template> -->
        <template #footer>
          <div class="search-btns">
            <el-button icon="refresh" @click="clearData">重置</el-button>
            <el-button icon="search" type="primary" @click="startSearch"
              >搜索</el-button
            >
          </div>
        </template>
      </crv-from>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue'
import CrvFrom, { IForm } from '@/base-ui/form'

export default defineComponent({
  name: 'page-search',
  components: {
    CrvFrom
  },
  props: {
    searchConfig: {
      type: Object as PropType<IForm>,
      required: true
    }
  },
  emits: ['startSearch'],
  setup(props, { emit }) {
    let originData: any = {}

    props.searchConfig.formItems.forEach((item) => {
      originData[item.field] = ''
    })

    const formData = ref(originData)
    const startSearch = () => {
      emit('startSearch', formData.value)
    }
    const clearData = () => {
      for (var key in formData.value) {
        formData.value[key] = ''
      }
      emit('startSearch', formData.value)
    }
    return {
      startSearch,
      clearData,
      formData
    }
  }
})
</script>

<style scoped lang="less">
.search {
  .search-btns {
    text-align: right;
    padding: 0px 10px 10px 0px;
  }
}
</style>
